package com.lgx.mall.business.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.lgx.common.entity.IdGenerator;

/**
 * 订单明细
 * 
 * @author acer
 *
 */
@Entity
@Table(name = "TM_ORDER_DETAIL")
public class OrderDetail implements Serializable {

	private static final long serialVersionUID = -6630098553901263089L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator=IdGenerator.TM_ORDER_DETAIL_ID)
	@TableGenerator(
			name = IdGenerator.TM_ORDER_DETAIL_ID,
			table = IdGenerator.GENERATOR_TABLE,
			pkColumnName = IdGenerator.GEN_NAME,
			pkColumnValue = IdGenerator.TM_ORDER_DETAIL_ID,
			valueColumnName = IdGenerator.GEN_VALUE,
			initialValue = 1,
			allocationSize = 1
	)
	private long id;
	
	/**
	 * 所属订单
	 */
	@ManyToOne(targetEntity=Order.class,cascade={CascadeType.REFRESH,CascadeType.MERGE},optional=true)
	@JoinColumn(name = "order_id")
	private Order order;
	
	/**
	 * 订单类型，1:实物商品，2：短信兑换类
	 */
	private String type;
	
	/**
	 * 对应实体类的全限定名
	 */
	private String entityType = "com.lgx.mall.core.entity.Product";
	
	/**
	 * 购买产品Id
	 */
	private long entityId;
	
	/**
	 * 名称
	 */
	private String entityName;
	
	/**
	 * 图片路径
	 */
	private String entityImg;
	
	/**
	 * url
	 */
	private String entityUrl = "";
	
	/**
	 * 单价
	 */
	private Double price;
	
	/**
	 * 购买数量
	 */
	private int amount;
	
	/**
	 * 描述
	 */
	private String description;

	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getEntityType() {
		return entityType;
	}

	public void setEntityType(String entityType) {
		this.entityType = entityType;
	}

	public long getEntityId() {
		return entityId;
	}

	public void setEntityId(long entityId) {
		this.entityId = entityId;
	}

	public String getEntityName() {
		return entityName;
	}

	public void setEntityName(String entityName) {
		this.entityName = entityName;
	}

	public String getEntityImg() {
		return entityImg;
	}

	public void setEntityImg(String entityImg) {
		this.entityImg = entityImg;
	}

	public String getEntityUrl() {
		return entityUrl;
	}

	public void setEntityUrl(String entityUrl) {
		this.entityUrl = entityUrl;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	/**
	 * 返回商品积分总额，数量*单件积分
	 * @return
	 */
	public Double predict(){
		return getPrice() * getAmount();
	}
	
}
